home *** CD-ROM | disk | FTP | other *** search
- #include "lib.h"
-
- /* Integer to ASCII for signed decimal integers. */
-
- static int next;
- #ifdef __GNUC__ /* ACK cc does not handle `#if defined..' correctly so */
- /* we have to do these conditionals this way */
- #ifndef __MSHORT__
- static char qbuf[14];
- #else
- static char qbuf[8];
- #endif
- #else
- static char qbuf[8];
- #endif
-
- char *itoa(n)
- int n;
- {
- register int r, k;
- int flag = 0;
-
- /* bug fix - did'nt handle -32768 correctly
- * ++jrb bammi@dsrgsun.ces.cwru.edu
- */
- #ifdef __GNUC__
- #ifdef __MSHORT__
- if(n == -32768) { /* ACK C Users WATCH OUT, ITS BRAINDAMAGED, and the
- explaination forthcoming for this on the net
- from the people at V..U was even worse ,
- Gnu C does this correctly */
- strcpy(qbuf, "-32768");
- return qbuf;
- }
- #else
- if(n == -2147483648L) { /* ACK C barfs here */
- strcpy(qbuf, "-2147483648");
- return qbuf;
- }
- #endif
- #else
- if(n == -32768) {
- strcpy(qbuf, "-32768");
- return qbuf;
- }
- #endif
-
- next = 0;
- if (n < 0) {
- qbuf[next++] = '-';
- n = -n;
- }
- if (n == 0) {
- qbuf[next++] = '0';
- } else {
-
- #ifdef __GNUC__
- #ifdef __MSHORT__
- k = 10000;
- #else
- k = 1000000000;
- #endif
- #else
- k = 10000;
- #endif
- while (k > 0) {
- r = n/k;
- if (flag || r > 0) {
- qbuf[next++] = '0' + r;
- flag = 1;
- }
- n -= r * k;
- k = k/10;
- }
- }
- qbuf[next] = 0;
- return(qbuf);
- }
-